$(document).ready(function() {


$("#home-btn").on("click",activeHome());


});



function listProduct() {
	

	$.ajax({
		type: "POST",
		url: "./listaProdottiPersonali",
		data: { },
		dataType: "xml",

		success: function(data){
			



			var result = "";

			$(data).find('report').each(function() {
				
				var titolo = $(this).find('titolo').text();
				var autori = $(this).find('autori').text();
				var stato = $(this).find('stato').text().toLowerCase();
				var anno_pubb = $(this).find('anno_pubb').text();
				var id_prod = $(this).find('prod_id').text();
				
                var classeIcona = "";
                var altText = "";
				
				if(stato == "draft") {
					classeIcona="glyphicon glyphicon-time";
					altText = "Draft";
                }
				else if(stato == "completo") {
					classeIcona="glyphicon glyphicon-ok-circle";
					altText = "Completo";
				}
				else if(stato == "accettato") {
					classeIcona="glyphicon glyphicon-ok";
					altText = "Accettato";
				}
				else {
					classeIcona="glyphicon glyphicon-star";
					altText = "Validato";
				}
				
				
	
                result+=  
            		"<li style='margin-bottom:5px; -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px;' onmouseover='tbodyHover(this)' onmouseout='tbodyOut(this)' id='"+id_prod+"' onclick='redirect(this)'>" +
            		"<table   >" +
            		"<tr> " +
            		" <td style='width:40%;'> <h3 class='titolo'>"+titolo+"</h3></td>"+
            		" <td style='width:40%;'>  <h4 class='autori'>"+autori+"</h4></td>"+
            		" <td style='width:40%;'>  <h4><p class='stato' hidden>"+stato+"</p> <span class=' "+classeIcona+"' title='"+altText+"'></span></h4></td>"+
            		" <td style='width:40%;'> <h4 class='data'>"+anno_pubb+"</h4></td>"+
            		"</tr> </table>"+
            		"</li>";
                	
                	
				

			}); // FINE EACH FUNCTION
			
			$(result).appendTo("#list_personal_product");
			$("#container_personal_product").show();
			var options = { valueNames: ['titolo' , 'autori' , 'data' , 'stato' , 'pubblico' ]};
            var userList = new List('prodotti', options);

		}
	
	


});
	
	
}


function tbodyHover(x) {
	
  $( x ).css("background-color","#F0AD4E");
  $(x).css('cursor','pointer');
		
	
}

function tbodyOut(x) {

    $( x ).css("background-color","#eeeeee");
    $(x).css('cursor','auto');
  
}

function activeHome() {
	
	$("li").removeClass("active");	
	$("li#home-btn").addClass("active");
	$("#white-notify").removeClass("white-notify");
}

function redirect(x)
{
	var id=x.id;
	document.location.href="./visualizzaProdotto.jsp?#"+id;


}